package com.tjn.methods;

/**
 * @author 陶镓妮
 * @version 1.0
 * yield()与 join()
 */
public class ThreadMethod02 {
    public static void main(String[] args) throws InterruptedException {
        T t1 = new T();
        t1.start();
        for (int i = 0; i < 20; i++) {
            Thread.sleep(1000);
            System.out.println("我是小弟" + i);
            if(i == 5){
                System.out.println("让大哥先。。");
                //让T线程插队到主线程去
                t1.join();//join()是真的可以插队先执行的
                //t1.yield();//yield()只是让出cpu，不保证一定插队，插队不一定成功。
                System.out.println("大哥完了，小弟继续");
            }
        }
    }
}

class T extends Thread{
    @Override
    public void run() {
        for (int i = 0; i < 20; i++) {
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            System.out.println("让大哥插队" + i);
        }
    }
}